import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const menus = [
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  }, {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }, {
    path: '/',
    component: Layout,
    children: [{
      path: '/index',
      name: 'Index',
      component: () => import('@/views/index'),
      meta: {title: '首页', icon: 'el-icon-s-home'}
    }]
  }, {
    path: '/projectMgr',
    component: Layout,
    meta: {title: '项目管理', icon: 'el-icon-view'},
    children: [{
      path: '/project',
      name: 'Project',
      component: () => import('@/views/generator/project'),
      meta: {title: '项目管理', icon: 'el-icon-connection'}
    }, {
      path: '/projectGenHis',
      name: 'ProjectGenHis',
      component: () => import('@/views/generator/projectGenHis'),
      meta: {title: '生成记录', icon: 'el-icon-document'}
    }]
  }, {
      path: '/sys',
      name: 'Sys',
      component: Layout,
      alwaysShow: true,
      meta: {title: '系统管理', icon: 'el-icon-setting'},
      children: [{
        path: "/account",
        name: 'Account',
        component: () => import('@/views/sys/account'),
        meta: {title: '账号管理', icon: 'el-icon-user'}
    }]
  }]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({x: 0, y: 0}),
  // routes: constantRoutes
  routes: menus
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
